package com.ruoyi.web.ydz.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.ydz.domain.InvitationCollect;
import com.ruoyi.web.ydz.service.IInvitationCollectService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 用户收藏Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/ydz/invcollect")
public class InvitationCollectController extends BaseController
{
    @Resource
    private IInvitationCollectService invitationCollectService;

    /**
     * 查询用户收藏列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:invcollect:list')")
    @GetMapping("/list")
    public TableDataInfo list(InvitationCollect invitationCollect)
    {
        startPage();
        List<InvitationCollect> list = invitationCollectService.selectInvitationCollectList(invitationCollect);
        return getDataTable(list);
    }

    /**
     * 导出用户收藏列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:invcollect:export')")
    @Log(title = "用户收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InvitationCollect invitationCollect)
    {
        List<InvitationCollect> list = invitationCollectService.selectInvitationCollectList(invitationCollect);
        ExcelUtil<InvitationCollect> util = new ExcelUtil<InvitationCollect>(InvitationCollect.class);
        util.exportExcel(response, list, "用户收藏数据");
    }

    /**
     * 获取用户收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('ydz:invcollect:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(invitationCollectService.selectInvitationCollectById(id));
    }

    /**
     * 新增用户收藏
     */
    @PreAuthorize("@ss.hasPermi('ydz:invcollect:add')")
    @Log(title = "用户收藏", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    public AjaxResult add(@RequestBody InvitationCollect invitationCollect)
    {
        return toAjax(invitationCollectService.insertInvitationCollect(invitationCollect));
    }

    /**
     * 修改用户收藏
     */
    @PreAuthorize("@ss.hasPermi('ydz:invcollect:edit')")
    @Log(title = "用户收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InvitationCollect invitationCollect)
    {
        return toAjax(invitationCollectService.updateInvitationCollect(invitationCollect));
    }

    /**
     * 删除用户收藏
     */
    @PreAuthorize("@ss.hasPermi('ydz:invcollect:remove')")
    @Log(title = "用户收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(invitationCollectService.deleteInvitationCollectByIds(ids));
    }

    /*
    * 根据帖子ID删除用户收藏
    * */
    @PreAuthorize("@ss.hasPermi('ydz:invcollect:remove')")
    @Log(title = "删除用户收藏", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeCollect")
    public AjaxResult removeCollect(@PathVariable Long invitationId){
        return toAjax(invitationCollectService.deleteInvitationCollectById(invitationId));
    }
}
